package com.topscomm.pm.script;

import com.topscomm.cbo.pojo.CboApprovalNodeInsEntity;
import com.topscomm.pm.PmScript;
import com.topscomm.pm.pojo.PmFinishedApplyEntity;
import com.topscomm.pm.pojo.PmProjectEntity;
import com.topscomm.pm.service.impl.PmFinishedApplyService;
import com.topscomm.pm.service.impl.PmProjectService;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.SpringUtil;
import com.topscomm.tap.ITapService;
import com.topscomm.tap.TapEntity;

import java.util.Date;

public class PmFinishedScript extends PmScript {
    /**
     * @author: wushenghong
     * @date: 2020/6/4
     * @description: 更新项目档案
     */
    public void updateProject(ITapService service, TapEntity entity) throws Exception {
        // 审批节点实例
        CboApprovalNodeInsEntity nodeIns = (CboApprovalNodeInsEntity) entity;
        String sourceId = ConvertUtil.convertToString(nodeIns.getSourceid());
        PmProjectService pmProjectService = (PmProjectService) SpringUtil.getBean("pmProjectService");
        PmFinishedApplyService pmFinishedApplyService = (PmFinishedApplyService) SpringUtil.getBean("pmFinishedApplyService");
        PmFinishedApplyEntity pmFinishedApplyEntity = pmFinishedApplyService.queryById(sourceId);
        if (pmFinishedApplyEntity != null) {
            Date actualEndTime = pmFinishedApplyEntity.getActualendtime();//完工时间
            PmProjectEntity pmProjectEntity = pmProjectService.queryById(ConvertUtil.convertToString(pmFinishedApplyEntity.getProjectid()));
            if (pmProjectEntity != null) {
                // 更新项目计划完工时间
                pmProjectEntity.setActualendtime(actualEndTime);
                pmProjectEntity.setProjectstate(3);//将项目状态置为待闭环
                pmProjectService.updateEntity(pmProjectEntity);
            }
        }
    }
}
